package com.example.arithmeticleetcode.leetcode.nov;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-24 09:33
 **/
public class Demo15 {



    public ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;

        ListNode headResult = new ListNode(0);
        ListNode tailResult = headResult;

        while (head != null) {
            if (head.val != val) {
                tailResult.next = head;
                tailResult = head;
            }
            head = head.next;
        }
        tailResult.next = null;
        return headResult.next;
    }
}



